package com.esteel.settlement.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.esteel.settlement.dao.SettPlatInfoRepository;
import com.esteel.settlement.entity.TbSettPlatInfo;
import com.esteel.settlement.service.SettPlatInfoService;

@Service
@Transactional
@CacheConfig(cacheManager="cacheManager",cacheNames="platinfo")
public class SettPlatInfoServiceImpl implements SettPlatInfoService {

	@Autowired
	private SettPlatInfoRepository settPlatInfoRepository;
	
	@Override
	@CachePut(key="#result.infoId")
	public TbSettPlatInfo save(TbSettPlatInfo tbSettPlatInfo) {
		return settPlatInfoRepository.save(tbSettPlatInfo);
	}

	@Override
	@Cacheable(key="p0")
	public TbSettPlatInfo findOne(long id) {
		return settPlatInfoRepository.findOne(id);
	}
	
	@Cacheable(key="#result.infoId")
	public TbSettPlatInfo findAll(){
		List<TbSettPlatInfo> list = settPlatInfoRepository.findTbSettPlatInfo();
		if (list==null||list.size()==0){
			return null;
		}else{
			return list.get(0);
		}
	}

}
